package cst.a931xmc.yuejian20.Fragment.Home;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import cst.a931xmc.yuejian20.Adapter.MatchAdapter;
import cst.a931xmc.yuejian20.Bean.MatchBean;
import cst.a931xmc.yuejian20.Listener.Listener;
import cst.a931xmc.yuejian20.Model.MatchModel;
import cst.a931xmc.yuejian20.R;

public class MatchFragment extends Fragment {
    private RecyclerView recyclerView;
    private MatchAdapter adapter;
    private RecyclerView.LayoutManager layoutManager;
    private Listener<List<MatchBean>> listener;
    private MatchModel model;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_hmatch,container,false);
        initViews(view);
        initData();
        model=new MatchModel();
        model.getList(listener);
        return view;
    }

    public void initViews(View view){
        recyclerView = view.findViewById(R.id.rv_match);
        adapter = new MatchAdapter(getActivity());
        layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
    }

    public void initData(){
        listener=new Listener<List<MatchBean>>() {
            @Override
            public void onResponse(List<MatchBean> list) {
                recyclerView.setAdapter(adapter);
                adapter.setList(list);
            }

            @Override
            public void onFail(String Massage) {

            }
        };
    }
}
